<?php 
 
 class WebsetController extends AuthController{
 	public function index(){
 		$model = K('Config');
		if(IS_POST){
			foreach(Q('post.') as $k => $v){
				$model->where("name='{$k}'")->update(array('value'=>$v));
			}
			//把数据库的配置项写入Application/Common/webConfig.php文件里面
			$data = $model->all();
			//重组数组
			$temp = array();
			foreach($data as $v){
				$temp[$v['name']] = $v['value'];
			}
			//代码合法化
			$temp = var_export($temp,true);
			$str = <<<str
<?php
if (!defined("HDPHP_PATH"))exit('No direct script access allowed');
//更多配置请查看hdphp/Config/config.php
return {$temp};
?>
str;
			file_put_contents(APP_CONFIG_PATH . '/conf.php', $str);
			
			$this->success('修改成功');
		}
		$data = $model->all();
		$this->assign('data',$data);
 	    $this->display();
 	}
 }
